<!DOCTYPE html>
<html lang="zh-cn">
    <head>
        <meta charset="UTF-8"/>
        <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
        <title>inline-block结合伪元素实现居中</title>
        <style>
            *{
                margin: 0;
                padding: 0;
            }
            .block {
              text-align: center;
              background: #c0c0c0;
              border: #a0a0a0 solid 1px;
              margin: 20px;
            }
             
            .block:before {
              content: '\200B';
            /*   content: '';
              margin-left: -0.25em; */
              display: inline-block;
              height: 100%; 
              vertical-align: middle;
             }
             
            .centered {
              display: inline-block;
              vertical-align: middle;
              width: 300px;
              padding: 10px 15px;
              border: #a0a0a0 solid 1px;
              background: #f5f5f5;
             }
        </style>
    </head>
    <body>
        <div class="block" style="height: 300px;">
            
            <div class="centered">
                <h1>Some text</h1>
                <p>But he stole up to us again, and suddenly clapping his hand on my shoulder, said&mdash;"Did ye see anything looking like men going towards that ship a while ago?"</p>
            </div>
            
        </div>

        <div class="block" style="height: 200px;">
            
            <div class="centered">
                <h1>Some text</h1>
                <p>But he stole up to us again, and suddenly clapping his hand on my shoulder, said&mdash;"Did ye see anything looking like men going towards that ship a while ago?"</p>
            </div>
            
        </div>

        <div class="block" style="height: 600px;">
            
            <div class="centered">
                <h1>Some text</h1>
                <p>But he stole up to us again, and suddenly clapping his hand on my shoulder, said&mdash;"Did ye see anything looking like men going towards that ship a while ago?"</p>
            </div>
            
        </div>
    </body>
</html>